package com.zbkj.admin.controller.platform;

import com.github.pagehelper.PageInfo;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.pojo.request.PageParamRequest;
import com.zbkj.dal.pojo.request.ba.ConcludeRecycleRequest;
import com.zbkj.dal.pojo.request.ba.RecycleQueryRequest;
import com.zbkj.dal.pojo.response.ba.RecycleDetailResponse;
import com.zbkj.dal.pojo.response.ba.RecycleResponse;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.dal.common.utils.SecurityUtil;
import com.zbkj.dal.pojo.vo.LoginUserVo;
import com.zbkj.service.service.RecycleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author tianzhonghai
 * 2023/10/8 13:12
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/recycle")
@Api(tags = "回收寄卖")
public class RecycleController {
    @Autowired
    private RecycleService recycleService;

    //    @PreAuthorize("hasAuthority('platform:seckill:time:interval:add')")
    @ApiOperation(value = "分页获取回收寄卖信息")
    @RequestMapping(value = "/pageRecycles", method = RequestMethod.POST)
    public CommonResult<CommonPage<RecycleResponse>> querySharesPaged(@RequestBody RecycleQueryRequest recycleQueryRequest, PageParamRequest pageParamRequest) {
        if (CollectionUtils.isNotEmpty(recycleQueryRequest.getTimes())) {
            recycleQueryRequest.setBeginDate(recycleQueryRequest.getTimes().get(0));
            recycleQueryRequest.setEndDate(recycleQueryRequest.getTimes().get(1));
        }
        PageInfo<RecycleResponse> sharePageInfo = recycleService.queryRecyclePaged(recycleQueryRequest, pageParamRequest);
        return CommonResult.success(CommonPage.restPage(sharePageInfo));
    }

    @ApiOperation(value = "回收寄卖信息详情")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    public CommonResult<RecycleDetailResponse> detail(@PathVariable("id")Integer id) {
        return CommonResult.success(recycleService.detail(id));
    }

    @ApiOperation(value = "评估判定回收寄卖")
    @RequestMapping(value = "/conclude", method = RequestMethod.POST)
    public CommonResult<Boolean> conclude(@RequestBody ConcludeRecycleRequest concludeRecycleRequest) {
        LoginUserVo loginUserVo = SecurityUtil.getLoginUserVo();
        concludeRecycleRequest.setOperatorId(loginUserVo.getUser().getId());
        return CommonResult.success(recycleService.conclude(concludeRecycleRequest));
    }

    @ApiOperation(value = "创建商品")
    @RequestMapping(value = "/createProduct/{id}", method = RequestMethod.POST)
    public CommonResult<Boolean> createProduct(@PathVariable("id") Integer id) {
        return CommonResult.success(recycleService.createProduct(id));
    }
}
